package com.cy.pj.module.web;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//@ResponseBody
//@ControllerAdvice//次注解描述的类为spring web模块的全局异常处理类
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ArithmeticException.class)
   //@ResponseBody
    public String doHandleArithmeticException(ArithmeticException e){
        e.printStackTrace();
        System.out.println("GlobalExceptionHandler.doHandleArithmeticException()");
        return "计算过程中出现异常，异常信息为"+e.getMessage();
    }

    @ExceptionHandler(RuntimeException.class)
    //@ResponseBody
    public String doHandleRuntimeException(RuntimeException e){
        e.printStackTrace();
        System.out.println("GlobalExceptionHandler.doHandleRuntimeException()");
        return "计算过程中出现异常，异常信息为"+e.getMessage();
    }

    @ExceptionHandler(Throwable.class)
    //@ResponseBody
    public String doHandleThrowable(Throwable e){
        e.printStackTrace();
        System.out.println("GlobalExceptionHandler.doHandleThrowable()");
        return "系统维护中";
    }
}
